<template>
  <div class="content">
    <div class="warning">
      <img src="../../../assets/trumpet@2x.png" width="18px" height="18px" />
      <span class="warning_font">库存告急</span>
      <div @click="toList">
        <el-carousel
          height="20px"
          :interval="2000"
          style="width: 400px;margin-left: 10px;cursor: pointer;"
          direction="vertical"
          indicator-position="none"
          :autoplay="true"
        >
          <el-carousel-item v-for="item in 3" :key="item">
            <div>奥利司他胶囊九华康 — 仅剩{{ item }}件</div>
          </el-carousel-item>
        </el-carousel>
      </div>
    </div>
    <div class="top">
      <el-row>
        <el-col :span="8">
          <div class="left" style="border-right: 4px solid #F5F5F5;">
            <div class="top">
              <div class="top_size" style="display: flex;align-items: center">
                <div
                  style="border: 2px solid #2D7EDF;display: inline-block;height: 12px;margin-right: 10px"
                ></div>
                <span
                  style="display: inline-block;
font-weight: 600;
font-size: 17px;color:#333;"
                >
                  未完成数据
                </span>
              </div>
            </div>
            <div class="bottom">
              <div class="NoOrderInStock">
                <span
                  style="font-weight: 400;font-size: 13px;
color: #333333;text-align: left"
                  >未备货订单数</span
                >
                <span style="text-align: center;">{{
                  "物流审批-待备货" | filterName(this)
                }}</span>
              </div>
              <div class="NoOrderInStock">
                <span
                  style="font-weight: 400;font-size: 13px;
color: #333333;text-align: left"
                  >未发货订单数</span
                >
                <span style="text-align: center;">{{
                  "物流审批-已备货" | filterName(this)
                }}</span>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="16">
          <div
            class="left"
            style="min-width: 360px;border-left: 4px solid rgb(245,245,245);"
          >
            <div class="top">
              <div class="top_size" style="display: flex;align-items: center">
                <div
                  style="border: 2px solid #2D7EDF;display: inline-block;height: 12px;margin-right: 10px"
                ></div>
                <div
                  style="display: inline-block;
font-weight: 600;
font-size: 17px;"
                >
                  订单总汇
                </div>
              </div>
            </div>
            <div class="bottom">
              <div class="NoOrderInStock">
                <span
                  style="font-weight: 400;font-size: 13px;
color: #333333;text-align: left"
                  >{{ "订单日总汇" }}</span
                >
                <span style="text-align: center;">{{
                  "订单日总汇" | filterName(this)
                }}</span>
              </div>
              <div class="NoOrderInStock">
                <span
                  style="font-weight: 400;font-size: 13px;
color: #333333;text-align: left"
                  >{{ "订单近七天总汇" }}</span
                >
                <span style="text-align: center;">{{
                  "订单近七天总汇" | filterName(this)
                }}</span>
              </div>
              <div class="NoOrderInStock">
                <span
                  style="font-weight: 400;font-size: 13px;
color: #333333;text-align: left"
                  >{{ "订单当月总汇" }}</span
                >
                <span style="text-align: center;">{{
                  "订单当月总汇" | filterName(this)
                }}</span>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="bottom">
      <div class="topBorder">
        <div class="top">
          <div
            class="top_size"
            style="min-width: 219px;display: flex;align-items: center"
          >
            <div
              style="border: 2px solid #2D7EDF;display: inline-block;height: 12px;margin-right: 10px"
            ></div>
            <div
              style="display: inline-block;
font-weight: 600;
font-size: 17px;"
            >
              库存数据
            </div>
          </div>
        </div>
      </div>
      <div class="echarts">
        <div
          style="flex:1;display:flex;justify-content: space-between;flex-direction: column;"
        >
          <div class="title">
            <div
              style="border: 2px solid #2D7EDF;display: inline-block;height: 10px;margin-right: 10px"
            ></div>
            <span>出库数据</span>
          </div>
          <div class="contextBorder">
            <div
              class="context"
              v-for="(item, index) in inventoryData.出库"
              :key="item.label"
              style="margin-right:40px;"
            >
              <span style="font-size:14px;">{{ item.label }}</span>
              <div class="contextChil">
                <span
                  style="font-size:24px;font-weight:600;color:#333333;text-align: center;"
                  >{{ item.value }}</span
                >
                <!-- <span style="font-size:14px;margin-left:5px;"
                  >占总人数比30%</span
                > -->
              </div>
            </div>
          </div>
        </div>
        <div
          style="flex:1;justify-content: space-between;flex-direction: column;"
        >
          <div class="title">
            <div
              style="border: 2px solid #2D7EDF;display: inline-block;height: 10px;margin-right: 10px"
            ></div>
            <span>入库数据</span>
          </div>
          <div class="contextBorder">
            <div
              class="context"
              v-for="(item, index) in inventoryData.入库"
              :key="item.label"
              style="margin-right:40px;"
            >
              <span style="font-size:14px;">{{ item.label }}</span>
              <div class="contextChil">
                <span
                  style="font-size:24px;font-weight:600;color:#333333;text-align: center;"
                  >{{ item.value }}</span
                >
                <!-- <span style="font-size:14px;margin-left:5px;"
                  >占总人数比30%</span
                > -->
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div style="display:flex;padding:10px 20px;background:#fff;">
      <div id="chartLineBox" style="width: 45%; height: 450px"></div>
      <div id="chartLineBox1" style="width: 45%; height: 450px"></div>
    </div>
  </div>
</template>
<script>
import * as echarts from "echarts";
require("echarts/theme/shine");
export default {
  data() {
    return {
      unfinishedData: [], //未完成数据
      inventoryData: [], //库存数据
      orderConcourse: [], //订单总汇
    };
  },
  created() {
    this.getList();
  },
  updated() {
    this.resizeT();
  },
  activated() {
    this.resizeT();
  },
  filters: {
    filterName(value, that) {
      let temp = 0;
      if(that){
        temp = that.unfinishedData.find((e) => e.label === value);
      }
      return temp ? temp.value : 0;
    },
  },
  methods: {
    resizeT() {
      if (this.chartLine) {
        this.chartLine.resize();
      }
      if (this.chartLine1) {
        this.chartLine1.resize();
      }
      window.onresize = () => {
        if (this.chartLine) {
          this.chartLine.resize();
        }
        if (this.chartLine1) {
          this.chartLine1.resize();
        }
      };
    },
    getList() {
      this.axios
        .post("/order/v1/LogisticsHome/logistics/unfinishedData")
        .then((res) => {
          this.unfinishedData = res.data;
        });
      this.axios.post("/order/v1/LogisticsHome/inventoryData").then((res) => {
        this.inventoryData = res.data;
        this.drawLineChart();
      });
    },
    toList() {
      this.$router.push({
        path: "logisticsSystem/addStorageList",
        query: {
          type: 1,
        },
      });
    },
    drawLineChart() {
      this.chartLine = echarts.init(
        document.getElementById("chartLineBox"),
        null,
        {
          renderer: "svg",
        }
      );
      this.chartLine1 = echarts.init(
        document.getElementById("chartLineBox1"),
        null,
        {
          renderer: "svg",
        }
      );
      this.chartLine.clear();
      this.chartLine1.clear();

      let outArray = [];
      for (let e of this.inventoryData.出库) {
        outArray.push({ name: e.label, value: e.value });
      }
      // 指定图表的配置项和数据
      var option = {
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          data: this.inventoryData.出库.map((e) => e.label),
          itemHeight: 5,
          itemWidth: 5,
          x: "right", //可设定图例在左、右、居中
          y: "center",
        },
        color: ["#9580FF", "#BFB3FF"],

        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: ["50%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              formatter: "{b}: {c}件 \n\n占比{d}%",
              position: "center",
              textStyle: {
                color: "#000",
              },
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "18",
                fontWeight: "bold",
              },
            },
            data: outArray,
          },
        ],
      };
      // 指定图表的配置项和数据
      let inArray = [];
      if (this.inventoryData.入库) {
        for (let e of this.inventoryData.入库) {
          inArray.push({ name: e.label, value: e.value });
        }
      }
      var option1 = {
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          data: this.inventoryData.入库
            ? this.inventoryData.入库.map((e) => e.label)
            : [],
          itemHeight: 5,
          itemWidth: 5,
          x: "right", //可设定图例在左、右、居中
          y: "center",
        },

        color: ["#52CCA3", "#6699FF", "#B3CDFF"],
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: ["50%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              formatter: "{b}: {c}件 \n\n占比{d}%",
              position: "center",
              textStyle: {
                color: "#000",
              },
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "18",
                fontWeight: "bold",
              },
            },
            data: inArray,
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表。
      this.chartLine.setOption(option);
      this.chartLine1.setOption(option1);
    },
  },
};
</script>
<style lang="scss" scoped>
.content {
  span {
    word-break: keep-all;
    white-space: nowrap;
    overflow: hidden;
  }
  font-family: PingFangSC-Semibold, PingFang SC;
  .warning {
    display: flex;
    align-items: center;
    .warning_font {
      margin-left: 5px;
      font-size: 17px;
      font-weight: 600;
      color: #333333;
    }
  }
  .top {
    margin-top: 10px;
    .left {
      display: flex;
      flex-direction: column;
      background: #ffffff;
      border-radius: 10px;
      .top {
        border-bottom: 2px solid #f5f5f5;
        background: #ffffff;
        display: flex;
        justify-content: space-between;
        height: 40px;
        align-items: center;
        .top_size {
          height: min-content;
          padding-left: 5px;
          span {
            font-size: 12px;
            font-weight: 400;
            color: #999999;
            line-height: 17px;
            margin-left: 10px;
          }
        }
      }
      .bottom {
        padding: 20px 0px;
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        .NoOrderInStock {
          display: flex;
          flex-direction: column;
          text-align: left;
          font-weight: 600;
          font-size: 25px;
        }
      }
    }
  }
  .bottom {
    margin-top: 10px;
    .topBorder {
      display: flex;
      flex-direction: column;
      background: #ffffff;
      border-radius: 10px;
      .top {
        border-bottom: 2px solid #f5f5f5;
        background: #ffffff;
        display: flex;
        justify-content: space-between;
        padding: 5px 15px;
        .top_size {
          height: min-content;
          padding-left: 5px;
          span {
            font-size: 14px;
            font-weight: 400;
            color: #999999;
            line-height: 17px;
            margin-left: 10px;
          }
        }
      }
    }
    .echarts {
      background: #fff;
      padding: 50px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      .title {
        display: flex;
        align-items: center;
        font-weight: 600;
        font-size: 14px;
        color: #333333;
        margin-bottom: 10px;
      }
      .contextBorder {
        display: flex;
        flex-direction: row;
      }
    }
  }
}
</style>
